package com.guigu.tms.driver.controller;

import com.guigu.tms.commons.aggregation.entity.DriverJob;
import com.guigu.tms.commons.aggregation.entity.TaskTransport;
import com.guigu.tms.commons.aggregation.entity.TruckDriver;
import com.guigu.tms.commons.aggregation.feign.DriverFeign;
import com.guigu.tms.commons.base.feign.DriverFeignClient;
import com.guigu.tms.commons.entity.base.PdTruckDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/pdTruckDriver")
public class DriverController {

    @Autowired
    DriverFeignClient driverFeignClient;

    @Autowired
    DriverFeign driverFeign;

    @GetMapping("/ShowInformation")
    public PdTruckDriver ShowInformation(@RequestParam String UserId){
        return driverFeignClient.ShowInformation(UserId);
    }

    @PostMapping("/ShowTruckDriver")
    public List<DriverJob> ShowTruckDriver(@RequestBody Map<String,String> map){
        List<DriverJob> truckDrivers = driverFeign.ShowDriverJob(map);
        return truckDrivers;
    }

    @PostMapping("/Upload")
    public String Upload(MultipartFile file) throws IOException{
        // 获取文件名
        String fileName = file.getOriginalFilename();
        System.out.println(fileName);
        File file1 = new File("E:\\图片\\image",fileName);
        file.transferTo(file1);
        System.out.println("上传成功！");
        return fileName;
    }

    @PostMapping("/UploadJf")
    public int UploadJf(@RequestParam String jobId,@RequestParam String taskId,@RequestParam String deliverPicture,@RequestParam String transportCertificate){
        return driverFeign.UploadJf(jobId,taskId,deliverPicture,transportCertificate);
    }

    @PostMapping("/UploadTh")
    public int UploadTh(@RequestParam String jobId,@RequestParam String taskId,@RequestParam String cargoPickUpPicture){
        return driverFeign.UploadTh(jobId,taskId,cargoPickUpPicture);
    }

    @GetMapping("/CreateTaskPickupDispatch")
    public int CreateTaskPickupDispatch(@RequestParam String tripsId,@RequestParam(value = "endId", required = true) String endId){
        return driverFeign.CreateTaskPickupDispatch(tripsId,endId);
    }

}
